package cn.iocoder.yudao.module.biz.controller.admin.staffCertificate;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.biz.controller.admin.staffCertificate.vo.*;
import cn.iocoder.yudao.module.biz.dal.dataobject.staffCertificate.BizStaffCertificateDO;
import cn.iocoder.yudao.module.biz.convert.staffCertificate.BizStaffCertificateConvert;
import cn.iocoder.yudao.module.biz.service.staffCertificate.BizStaffCertificateService;

@Api(tags = "管理后台 - 证件管理")
@RestController
@RequestMapping("/biz/staff-certificate")
@Validated
public class BizStaffCertificateController {

    @Resource
    private BizStaffCertificateService staffCertificateService;

    @PostMapping("/create")
    @ApiOperation("创建证件管理")
    @PreAuthorize("@ss.hasPermission('biz:staff-certificate:create')")
    public CommonResult<String> createStaffCertificate(@Valid @RequestBody BizStaffCertificateCreateReqVO createReqVO) {
        return success(staffCertificateService.createStaffCertificate(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新证件管理")
    @PreAuthorize("@ss.hasPermission('biz:staff-certificate:update')")
    public CommonResult<Boolean> updateStaffCertificate(@Valid @RequestBody BizStaffCertificateUpdateReqVO updateReqVO) {
        staffCertificateService.updateStaffCertificate(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除证件管理")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermission('biz:staff-certificate:delete')")
    public CommonResult<Boolean> deleteStaffCertificate(@RequestParam("id") String id) {
        staffCertificateService.deleteStaffCertificate(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得证件管理")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermission('biz:staff-certificate:query')")
    public CommonResult<BizStaffCertificateRespVO> getStaffCertificate(@RequestParam("id") String id) {
        BizStaffCertificateDO staffCertificate = staffCertificateService.getStaffCertificate(id);
        return success(BizStaffCertificateConvert.INSTANCE.convert(staffCertificate));
    }

    @GetMapping("/list")
    @ApiOperation("获得证件管理列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('biz:staff-certificate:query')")
    public CommonResult<List<BizStaffCertificateRespVO>> getStaffCertificateList(@RequestParam("ids") Collection<String> ids) {
        List<BizStaffCertificateDO> list = staffCertificateService.getStaffCertificateList(ids);
        return success(BizStaffCertificateConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得证件管理分页")
    @PreAuthorize("@ss.hasPermission('biz:staff-certificate:query')")
    public CommonResult<PageResult<BizStaffCertificateRespVO>> getStaffCertificatePage(@Valid BizStaffCertificatePageReqVO pageVO) {
        PageResult<BizStaffCertificateDO> pageResult = staffCertificateService.getStaffCertificatePage(pageVO);
        return success(BizStaffCertificateConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出证件管理 Excel")
    @PreAuthorize("@ss.hasPermission('biz:staff-certificate:export')")
    @OperateLog(type = EXPORT)
    public void exportStaffCertificateExcel(@Valid BizStaffCertificateExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<BizStaffCertificateDO> list = staffCertificateService.getStaffCertificateList(exportReqVO);
        // 导出 Excel
        List<BizStaffCertificateExcelVO> datas = BizStaffCertificateConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "证件管理.xls", "数据", BizStaffCertificateExcelVO.class, datas);
    }

}
